#include <iostream>

#include <cstring>

#include <unistd.h>
#include <signal.h>

void print_pending()
{
    sigset_t pending;
    sigpending(&pending);
    for (int i = 31; i > 0; --i)
        std::cout << sigismember(&pending, i);
    std::cout << std::endl;
}

void handler(int signo)
{
    std::cout << "catch signo: " << signo << std::endl;
    while (true)
    {
        print_pending();
        sleep(1);
    }
}

int main()
{
    struct sigaction act, oact;
    memset(&act, 0, sizeof(act));
    memset(&oact, 0, sizeof(oact));

    sigemptyset(&act.sa_mask);
    sigaddset(&act.sa_mask, 1);
    sigaddset(&act.sa_mask, 3);
    sigaddset(&act.sa_mask, 4);
    act.sa_handler = handler;
    
    sigaction(2, &act, &oact);
    
    while (true)
    {
        std::cout << "I am a process: " << getpid() << std::endl;
        sleep(1);
    }

    return 0;
}